package touchpad;

import it.mouseclient.UDPClient;
import android.graphics.Point;
import android.view.MotionEvent;

import common.CommandType;

public class Scroll extends TouchpadCommand {

	private Point finger1, finger2;

	public Scroll(UDPClient client) {
		super(client);
		finger1 = new Point();
		finger2 = new Point();

	}

	@Override
	public boolean onUpTouch(MotionEvent m) {
		return true;

	}

	@Override
	public boolean onDownTouch(MotionEvent m) {
		return true;

	}

	@Override
	public boolean onMoveTouch(MotionEvent m) {
		boolean success = true;
		if (m.getPointerCount() == 2) {
			int maxMovement = 0;
			Point f1, f2;
			f1 = new Point();
			f2 = new Point();
			int f1_diff, f2_diff;

			TouchUtilities.getFingersPoint(m, f1, f2);
			f1_diff = f1.y - finger1.y;
			f2_diff = f2.y - finger2.y;
			if (f1_diff > f2_diff)
				maxMovement = f1_diff;
			else
				maxMovement = f2_diff;

			success = client.executeCommand(CommandType.SCROLL, maxMovement+"");
			TouchUtilities.getFingersPoint(m, finger1, finger2);
		}
		return success;

	}

	@Override
	public boolean onDownMultitouch(MotionEvent m) {
		if (m.getPointerCount() == 2) {
			TouchUtilities.getFingersPoint(m, finger1, finger2);
		}
		return true;
	}

	@Override
	public boolean onUpMultitouch(MotionEvent m) {
		return true;

	}

}
